package guijavacommander.actions;

import guijavacommander.FilePanel;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileNotFoundException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * User: Deady
 * Date: 16.07.2009
 * Time: 16:02:22
 */
public class CreateDirAction extends AbstractAction {

    Log logger = LogFactory.getLog(CreateDirAction.class);
    private FilePanel panel;

    public CreateDirAction(FilePanel panel) {
        this.panel = panel;
    }

    public void actionPerformed(ActionEvent e) {
        logger.debug("creating dir");
        String name = JOptionPane.showInputDialog("Enter folder name");
        if (name!=null) {
            File f = new File(panel.getCurrentFolder(), name);
            boolean res = f.mkdir();
            if (!res) {
                JOptionPane.showMessageDialog(panel, "Can't create folder "+name, "Errot", JOptionPane.ERROR_MESSAGE);
            }
            else {
                panel.refresh();
                try {
                    panel.selectFile(f);
                } catch (FileNotFoundException e1) {
                    e1.printStackTrace();
                }
            }
        }

        //TotalCommander.instance.getActivePanel().refresh();
    }


}
